﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Windows8Accelerator.Core.Xaml.Converters
{
    public class StringToUriConverter : IValueConverter
    {
        private static Uri _baseUri = new Uri("ms-appx:///");

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var url = (string)value;
            if (url.ToUpper().Contains("HTTP://") || url.ToUpper().Contains("HTTPS://"))
                return new Uri(url);

            return new Uri(_baseUri, url);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
